package com.wn55.hrms.web.controller;

import com.github.pagehelper.PageInfo;
import com.wn55.hrms.entity.Attendance;
import com.wn55.hrms.entity.RecruitChannel;
import com.wn55.hrms.mapper.AttendanceMapper;
import com.wn55.hrms.service.AttendanceService;
import com.wn55.hrms.service.vo.AttendanceVo;
import com.wn55.hrms.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author Mr.bai~
 * @version 1.0
 * @date 2022/5/5 15:08
 */
@RestController
@RequestMapping("attendance")
@Api(value = "本接口是用来操作出勤表功能")
public class AttendanceController {

    @Autowired
    AttendanceService attendanceService;

    @GetMapping("/attendanceList")
    @ApiOperation(value = "分页查询渠道列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",dataType = "int",name="now",value = "查询当前页",required = false,defaultValue = "1"),
            @ApiImplicitParam(paramType = "query",dataType = "int",name="size",value ="查询每页条数",required = false,defaultValue = "2"),
            @ApiImplicitParam(paramType = "query",dataType = "string",name="empName",value = "员工姓名",required = false)
    })
    public ResultResponse<PageInfo<AttendanceVo>> attendanceList(
            @RequestParam(value = "now", defaultValue = "1") Integer now,
            @RequestParam(value = "size", defaultValue = "2") Integer size,
            String empName){
        ResultResponse<PageInfo<AttendanceVo>> result = null;
        try {

            PageInfo<AttendanceVo> pageInfo = attendanceService.queryAttendance(now, size,empName);
            result = new ResultResponse<>(200, "查询成功", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(404, "查询失败");
        }
        return result;
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "根据标识ID删除考勤")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path",dataType = "int",name = "id",value = "考勤的ID标识")
    })
    public ResultResponse<Void> delete(@PathVariable("id") int id) {

        ResultResponse<Void> result = null;

        try {
            attendanceService.removeBykey(id);
            result = new ResultResponse<>(200, "删除角色成功!");
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(201, "删除角色失败!");
        }
        return result;
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加考勤信息")
    public ResultResponse<Void> add(@RequestBody Attendance attendance) {
        ResultResponse<Void> result = null;
        try {
            //attendance.setRecordingTime(new Date());
           attendanceService.add(attendance);
            result = new ResultResponse<>(200, "添加角色成功!");
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(201, "添加角色失败!");
        }
        return result;
    }


}
